package com.itcast.n1_内存调优;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.time.Duration;

/**
 * @program: jvm
 * @description: -Xmx500m
 * @author: flyduck
 * @create: 2024-10-16 17:23
 **/
public class Test14_内存泄漏问题4_缓存大对象不设置过期时间导致内存泄漏 {
    public static void main(String[] args) throws InterruptedException {
        Cache<Object, Object> build = Caffeine.newBuilder()
                //设置100ms之后就过期
                //.expireAfterWrite(Duration.ofMillis(100))
                .build();
        int count = 0;
        while (true){
            build.put(count++,new byte[1024 * 1024 * 10]);
            Thread.sleep(100L);
        }
    }
}
